﻿using Bandit.Helpers;
using Bandit.UI;
using Bandit.UI.MVVM;
using ETC.HallICElan2In1.Models;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ETC.HallICElan2In1.Windows
{
    /// <summary>
    /// FrmManage.xaml 的交互逻辑
    /// </summary>
    public partial class FrmConfig : Bandit.UI.BanditWindow
    {
        /// <summary>
        /// 视图模型
        /// </summary>
        private ViewModels.TestConfigViewModel ViewModel { get { return App.TestConfigViewModel; } }

        public FrmConfig()
        {
            InitializeComponent();

            this.Loaded += delegate
            {
                this.ViewModel.OnClick = new Bandit.UI.MVVM.CommandHandler(OnClick);

                this.DataContext = ViewModel;
            };

            this.Closed += (sender, e) =>
            {
                // 当窗口关闭后马上结束消息循环
                // System.Windows.Threading.Dispatcher.ExitAllFrames();
            };
        }

        #region UI Click Event

        private void OnClick(object parameter)
        {
            switch (parameter.ToString())
            {
                case "Close":
                    {
                        this.Close();
                    }
                    break;
                case "SaveSetting":
                    {
                        Core.TestConfig.SaveConfig();

                        this.ShowDialog(App.GetString("SaveSuccess"), App.GetString("Prompt"), MessageBoxButton.OK, Bandit.UI.DialogIcon.OK);

                        this.Close();
                    }
                    break;
                case "SelectElan_Software":
                    {
                        OpenFileDialog ofd = new OpenFileDialog();
                        ofd.Title = "Select BUI/CMI Software";
                        ofd.Filter = "Programm|*.exe";
                        if (ofd.ShowDialog().Value)
                        {
                            this.ViewModel.TestConfig.Elan_Software = ofd.FileName;
                        }
                    }
                    break;
                case "SelectElan_LogPath":
                    {
                        OpenFolderDialog ofd = new OpenFolderDialog();
                        if (ofd.ShowDialog())
                        {
                            this.ViewModel.TestConfig.Elan_LogPath = ofd.Folder;
                        }
                    }
                    break;
                default:
                    break;
            }
        }

        #endregion
    }
}
